$.ajax({
    url:constUrl+"CategoryServlet",
    type:'post',
    data:{
        operateType:"allList"

    },
    dataType:'json',
    success: function(responseText) {
        var typeHtml ='';
        var functionHtml = '';
        for(var i=0;i<responseText.datas.length;i++){
            if(responseText.datas[i].isFunction==1){
                typeHtml+='<option value="'+(responseText.datas[i].categoryId)+'" >'+responseText.datas[i].categoryName+'</option>'
        }else if(responseText.datas[i].isFunction==0){
                functionHtml+='<option value="'+(responseText.datas[i].categoryId)+'" >'+responseText.datas[i].categoryName+'</option>'
            }

        }
        $("#algorithm_type").append(typeHtml);
        $("#algorithm_function").append(functionHtml);
    },
    complete: function() {
    },
    error: function() {
    }
});

$.ajax({
    url:constUrl+"CompanyServlet",
    type:'post',
    data:{
        operateType:"showAll",
        onePageCount:"10",
        currentPage:"1"
    },
    dataType:'json',
    success: function(responseText) {
        var companyHtml ='';
        for(var i=0;i<responseText.datas.length;i++){
            companyHtml+='<option value="'+(responseText.datas[i].companyId)+'" >'+responseText.datas[i].companyName+'</option>'

        }
        $("#company_name").append(companyHtml);
    },
    complete: function() {
    },
    error: function() {
    }
});
var isSubmit = false
//输入数量
$("#addInputBtn").click(function () {
    addcount();
});
$("#deleteInputBtn").click(function () {
    deletecount();
});
function addcount() {
    var Num = document.getElementById("Num");
    var temp = Num.innerHTML;
    temp++;

    Num.innerHTML = temp;
    var inputpara = "inputpara"+temp;
    var para = "para" + temp;
    var inputName= "input_name" + temp;
    var inputType = "input_type"+temp;
    var inputDetail = "input_introduction"+ temp;
    var inputSuffix = "input_suffix"+temp;
    var inputTypeDiv = "input_type_div"+temp;
    var inputIntroDiv = "input_introduction_div"+temp;
    var inputSuffixDiv = "input_suffix_div"+temp;
    var acplaceholder = "名称"+temp;
    var cinDetailPlaceholder = "描述";
    var suffixAcplaceholder = "后缀"+temp;


    var inputHtml = '<div class="row '+inputpara+'" id="'+inputpara+'">' +
        '<div class="col-md-3 areaInput '+para+'">' +
        '        <input type="text" name="'+inputName+'" id="'+inputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
        ' </div>' +
        ' <div class="col-md-3 areaInput '+para+'">' +
        '        <select id="'+inputType+'" class="col-md-3"style="height: 37px;font-size:small"  >' +
        '                <option value="file" selected="selected">文件</option>' +
        '               <option value="directory">目录</option>' +
        '          </select>' +
        ' </div>'+
        '<div class="col-md-3 areaInput '+para+'" id="'+inputIntroDiv+'">' +
        '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+inputDetail+'" id="'+inputDetail+'" style="display: inline-block;font-size:small; height: 37px"">' +
        ' </div> ' +
        ' <div class="col-md-3 areaInput '+para+'" name="'+inputSuffixDiv+'">' +
        '        <input type="text" name="'+inputSuffix+'" id="'+inputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
        '</div>'+
        '</div>'
    $("#InputArea").append(inputHtml);

    var sel = document.getElementById(inputType);
    sel.onchange = function () {
        if(sel.options[sel.selectedIndex].value=="directory"){
            $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
            $('#'+inputIntroDiv).attr("class","col-md-6 areaInput "+para);

        }else if(sel.options[sel.selectedIndex].value=="file"){
            $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
            $('#'+inputIntroDiv).attr("class","col-md-3 areaInput "+para);
            var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+inputSuffixDiv+'">' +
                '        <input type="text" name="'+inputSuffix+'" id="'+inputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                '</div>';
            $('#'+inputpara).append(html2);
        }
    }
    //删除按钮
    var deleteBtn = document.getElementById("deleteInputBtn");
    deleteBtn.removeAttribute("disabled");
    return false;
}

//删除输入数量
function deletecount() {
    // event.preventDefault();
    var Area = document.getElementById("InputArea");
    // var addNum = document.getElementById("addNum");
    var Num = document.getElementById("Num");
    var temp = Num.innerHTML;
    var deleteLabel = document.getElementsByClassName("inputpara"+temp);
    Area.removeChild(deleteLabel[0]);
    temp--;
    Num.innerHTML = temp;
    if(temp === 0){
        var deleteBtn = document.getElementById("deleteInputBtn");
        deleteBtn.setAttribute("disabled","true");
    }
    return false;
}


//输出数量
$("#addOutputBtn").click(function () {
    addCout();
});
$("#deleteOutputBtn").click(function () {
    deletecout();
});
//增加输出数量
function addCout() {
    // event.preventDefault();
    var Area = document.getElementById("outputArea");
    var Num = document.getElementById("outputNum");
    var temp = Num.innerHTML;
    temp++;
    Num.innerHTML = temp;
    var outpara = "outpara"+temp;
    var para = "coutPara" + temp;
    var outputName= "output_name" + temp;
    var outputType = "output_type"+temp;
    var outputDetail = "output_introduction" + temp;
    var outputSuffix = "output_suffix"+temp;
    var outputTypeDiv = "output_type_div"+temp;
    var outputIntroDiv = "output_introduction_div"+temp;
    var outputSuffixDiv = "output_suffix_div"+temp;
    var acplaceholder = "名称"+temp;
    var cinDetailPlaceholder = "描述";
    var suffixAcplaceholder = "后缀"+temp;



    var outputHtml = '<div class="row '+outpara+'" id="'+outpara+'">' +
        '<div class="col-md-3 areaInput '+para+'">' +
        '        <input type="text" name="'+outputName+'" id="'+outputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
        '</div>' +
        ' <div class="col-md-3 areaInput '+para+'">' +
        '        <select id="'+outputType+'" class="col-md-3"  style="height: 37px;font-size:small">' +
        '                <option value="file" selected="selected">文件</option>' +
        '                <option value="directory">目录</option>' +
        '            </select>' +
        '    </div>'+
        ' <div class="col-md-3  areaInput '+para+'" id="'+outputIntroDiv+'">' +
        '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+outputDetail+'" id="'+outputDetail+'" style="display: inline-block;font-size:small; height: 37px">' +
        ' </div>' +
        ' <div class="col-md-3  areaInput '+para+'" name="'+outputSuffixDiv+'">' +
        '        <input type="text" placeholder="'+suffixAcplaceholder+'" name="'+outputSuffix+'" id="'+outputSuffix+'" style="display: inline-block;font-size:small; height: 37px">' +
        ' </div>' +
        '</div>'
    $("#outputArea").append(outputHtml);
    var sel = document.getElementById(outputType);
    sel.onchange = function () {
        if(sel.options[sel.selectedIndex].value=="directory"){
            $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
            $('#'+outputIntroDiv).attr("class","col-md-6 areaInput "+para);

        }else if(sel.options[sel.selectedIndex].value=="file"){
            $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
            $('#'+outputIntroDiv).attr("class","col-md-3 areaInput "+para);
            var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+outputSuffixDiv+'">' +
                '        <input type="text" name="'+outputSuffix+'" id="'+outputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                '</div>';
            $('#'+outpara).append(html2);
        }
    }
    //删除按钮
    var deleteBtn = document.getElementById("deleteOutputBtn");
    deleteBtn.removeAttribute("disabled");
    return false;
}

//删除输出数量
function deletecout() {

    // event.preventDefault();
    var Area = document.getElementById("outputArea");
    var Num = document.getElementById("outputNum");
    var temp = Num.innerHTML;
    var deleteLabel = document.getElementsByClassName("outpara"+temp);
    Area.removeChild(deleteLabel[0]);
    temp--;
    Num.innerHTML = temp
    if(temp === 0){
        var deleteBtn = document.getElementById("deleteOutputBtn");
        deleteBtn.setAttribute("disabled","true")
    }
    return false;
}

//输入参数
$("#addParamBtn").click(function () {
    addCinPara();
});
$("#deleteParamBtn").click(function () {
    deleteCinPara();
});
//增加输入参数
function addCinPara() {
    // event.preventDefault();
    var Area = document.getElementById("paramArea");
    var Num = document.getElementById("paramNum");
    var temp = Num.innerHTML;
    temp++;
    Num.innerHTML = temp;
    var parames = "parames"+temp;
    var para = "cinPara" + temp;
    var paramType =  "param_id" + temp;
    var paramSymbol=  "param_symbol" + temp;
    var paramDetail=  "param_introduction" + temp;
    var defalt = "paramDefaultValue"+temp;

    var symbolPlace = "符号"+ temp;
    var cinDetailPlaceholder = "描述"+temp;
    var defaultsPlaceholder = "默认值"+temp;

    var paramHtml = '<div class="row '+parames+'"><div class="col-md-3 areaInput '+para+'">' +
        '        <input type="text" name="'+paramSymbol+'" id="'+paramSymbol+'" placeholder="'+symbolPlace+'" style="display: inline-block;font-size:small; height: 37px">' +
        '    </div>' +
        ' <div class="col-md-3 areaInput '+para+'">' +
        '        <select id="'+paramType+'" class="col-md-3"  style="' +
        '    height: 37px;font-size:small' +
        '"  >' +
        '                <option value="int" selected="selected">int</option>' +
        '                <option value="double">double</option>' +
        '                <option value="float">float</option>' +
        '                <option value="string">string</option>' +
        '            </select>' +
        '    </div>'+
        '    <div class="col-md-3 areaInput '+para+'">' +
        '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+paramDetail+'" id="'+paramDetail+'" style="display: inline-block;font-size:small; height: 37px">' +
        '    </div>'+
        '    <div class="col-md-3 areaInput '+para+'">' +
        '        <input type="text" placeholder="'+defaultsPlaceholder+'" name="'+defalt+'" id="'+defalt+'" style="display: inline-block;font-size:small; height: 37px">' +
        '    </div>'
    $("#paramArea").append(paramHtml);

    //删除按钮
    var deleteBtn = document.getElementById("deleteParamBtn");
    deleteBtn.removeAttribute("disabled");
    return false;
}

//删除输入参数
function deleteCinPara() {
    // event.preventDefault();
    var Area = document.getElementById("paramArea");
    var Num = document.getElementById("paramNum");
    var temp = Num.innerHTML;
    var deleteLabel = document.getElementsByClassName("parames" + temp);
    Area.removeChild(deleteLabel[0]);
    temp--;
    Num.innerHTML = temp;
    if(temp === 0){
        var deleteBtn = document.getElementById("deleteParamBtn");
        deleteBtn.setAttribute("disabled","true")
    }
}


function RepNumber(obj) {
    obj.value =obj.value.replace(/[^\d.]/g, "");
    if(obj.value>100){
        obj.value=100;
    }
    return false;
}

//详情预览
function checkInfo() {
    // var deleteLabel = document.getElementsByClassName("parames" + temp);
    var deleteLabel = document.getElementById("infoTable");
    var Area = document.getElementById("deleteLable");
    if(deleteLabel!=null){
        Area.removeChild(deleteLabel);
    }

    var ch_name = document.getElementById("name").value;
    var ch_version = document.getElementById("version").value;
    var ch_type_select = document.getElementById("algorithm_type");
    var ch_type_options = ch_type_select.options;
    var ch_type_index = ch_type_select.selectedIndex;
    if(ch_type_index==0){
        var ch_type = "";
    }else{
        var ch_type = ch_type_options[ch_type_index].text;
    }
    var ch_func_select = document.getElementById("algorithm_function");
    var ch_func_options = ch_func_select.options;
    var ch_func_index = ch_func_select.selectedIndex
    if(ch_func_index==0){
        var ch_func = "";
    }else{
        var ch_func = ch_func_options[ch_func_index].text;
    }

    // var ch_complane = document.getElementById("company_name").value;
    var ch_complane_select = document.getElementById("company_name");
    var ch_complane_options = ch_complane_select.options;
    var ch_complane_index = ch_complane_select.selectedIndex
    if(ch_complane_index==0){
        var ch_complane = "";
    }else{
        var ch_complane = ch_complane_options[ch_complane_index].text;
    }

    var ch_introduction = document.getElementById("introduction").value;
    var ch_suffix = document.getElementById("postfix").value;
    var ch_palatforme = document.getElementById("platform").value;
    /*var ch_minmemory = document.getElementById("Min_intrinsic").value;
    var ch_minCPU = document.getElementById("Min_CPU").value/100;*/


    var GPU=document.getElementsByName("GPU");
    for(var i=0;i<GPU.length;i++)
    {
        if(GPU[i].checked)
        {
            var ch_Gpu=GPU[i].value;
            break;
        }
        else
        {
            continue;
        }
    }
    if(ch_Gpu==undefined){
        ch_Gpu="";
    }
    var MPI=document.getElementsByName("MPI")
    for(var i=0;i<MPI.length;i++)
    {
        if(MPI[i].checked)
        {
           var ch_useMpi=MPI[i].value;
            break;
        }
        else
        {
            continue;
        }
    }
    if(ch_useMpi==undefined){
        ch_useMpi="";
    }
    var genetic=document.getElementsByName("genetic")
    for(var i=0;i<genetic.length;i++)
    {
        if(genetic[i].checked)
        {
            var ch_isGenetic=genetic[i].value;
            break;
        }
        else
        {
            continue;
        }
    }
    if(ch_isGenetic==undefined){
        ch_isGenetic="";
    }
    var ch_input_count_num=document.getElementById("Num").innerHTML;
    var ch_output_count_num=document.getElementById("outputNum").innerHTML;
    var ch_params_count_num=document.getElementById("paramNum").innerHTML
    var inputInfoStr="";
    for(var i=0;i< ch_input_count_num;i++)
    {
        var temp=i+1;
        var inputName= "input_name" +temp;
        inputInfoStr+=document.getElementById(inputName).value+"&nbsp;&nbsp;&nbsp;输入"+temp+"&nbsp;&nbsp;&nbsp;";
    }
    var outputInfoStr="";
    for(var i=0;i< ch_output_count_num;i++)
    {
        var temp=i+1;
        var outputName= "output_name" +temp;
        outputInfoStr+=document.getElementById(outputName).value+"&nbsp;&nbsp;&nbsp;输出"+temp+"&nbsp;&nbsp;&nbsp;";
    }
    var paramInfoStr ="";
    for(var i=0;i<ch_params_count_num;i++)
    {
        var temp=i+1;
        var paramSymbol=  "param_symbol" +temp;
        paramInfoStr+=document.getElementById(paramSymbol).value+"&nbsp;&nbsp;&nbsp;参数"+temp+"&nbsp;&nbsp;&nbsp;";
    }

    var paramFlieresString=$("#file").val();
    var str = paramFlieresString.split("\\");
    var paramFlieres = str[str.length-1];

    var ch_order =paramFlieres+"&nbsp;&nbsp;&nbsp;"+inputInfoStr+outputInfoStr+paramInfoStr;

    if(ch_useMpi=="true"){
        var ch_cupnum = document.getElementById("cpunum").value;
        var tableHtml = '<div class="am-u-sm-12 am-u-md-12" id="infoTable"><table class="am-table am-table-bordered am-table-radius am-table-striped">' +
            '                                        <tr><td style="width: 150px">算法名称</td><td id="ag_name" style="width: 295px">'+ch_name+'</td><td style="width: 150px">算法版本</td><td id="ag_version"style="width: 295px">'+ch_version+'</td></tr>' +
            '                                        <tr><td>算法类型</td><td id="ag_type">'+ch_type+'</td><td>算法功能</td><td id="ag_func">'+ch_func+'</td></tr>' +
            '                                        <tr><td>算法研制单位</td><td id="ag_complane">'+ch_complane+'</td><td>算法简介</td><td id="ag_introduction">'+ch_introduction+'</td></tr>' +
            '                                        <tr><td>算法后缀</td><td id="ag_sufficx">'+ch_suffix+'</td><td>使用平台</td><td id="palatforme">'+ch_palatforme+'</td></tr>' +
            '                                        <tr><td>是否使用GPU</td><td id="isuseGPU">'+ch_Gpu+'</td><td>是否使用MPI</td><td id="isuseMPI">'+ch_useMpi+'</td></tr>' +
            '                                        <tr><td>是否是遗传算法</td><td id="genetic">'+ch_isGenetic+'</td><td>CPU使用个数</td><td id="gupname">'+ch_cupnum+'</td></tr>' +
            '                                    </table>' +
            '                                    <table class="am-table am-table-bordered am-table-radius am-table-striped">' +
            '                                        <tr><td style="width: 150px">执行命令</td><td>'+ch_order+'</td></tr>' +
            '                                    </table></div>'
    }else{
        var tableHtml = '<div class="am-u-sm-12 am-u-md-12" id="infoTable"><table class="am-table am-table-bordered am-table-radius am-table-striped">' +
            '                                        <tr><td style="width: 150px">算法名称</td><td id="ag_name" style="width: 295px">'+ch_name+'</td><td style="width: 150px">算法版本</td><td id="ag_version"style="width: 295px">'+ch_version+'</td></tr>' +
            '                                        <tr><td>算法类型</td><td id="ag_type">'+ch_type+'</td><td>算法功能</td><td id="ag_func">'+ch_func+'</td></tr>' +
            '                                        <tr><td>算法研制单位</td><td id="ag_complane">'+ch_complane+'</td><td>算法简介</td><td id="ag_introduction">'+ch_introduction+'</td></tr>' +
            '                                        <tr><td>算法后缀</td><td id="ag_sufficx">'+ch_suffix+'</td><td>使用平台</td><td id="palatforme">'+ch_palatforme+'</td></tr>' +
            '                                        <tr><td>是否使用GPU</td><td id="isuseGPU">'+ch_Gpu+'</td><td>是否使用MPI</td><td id="isuseMPI">'+ch_useMpi+'</td></tr>' +
            '                                        <tr><td>是否是遗传算法</td><td id="genetic">'+ch_isGenetic+'</td><td></td><td ></td></tr>' +
            '                                    </table>' +
            '                                    <table class="am-table am-table-bordered am-table-radius am-table-striped">' +
            '                                        <tr><td style="width: 150px">执行命令</td><td>'+ch_order+'</td></tr>' +
            '                                    </table></div>'
    }

    $("#deleteLable").append(tableHtml);

}

//提交表单
function submit()
{
    if(!isSubmit){
        isSubmit = true;
        // event.preventDefault();
        var registerinfo=new Object();
        registerinfo.name=document.getElementById("name").value;
        input_count_num=document.getElementById("Num").innerHTML;

        var inputinfo=new Array();
        for(var i=0;i< input_count_num;i++)
        {
            var temp=i+1;
            var inputName= "input_name" +temp;
            var type = "input_type"+temp;
            var inputDetail = "input_introduction"+temp;
            var inputSufficcx = "input_suffix"+temp;
            if(document.getElementById(type).value=="file"){
                inputinfo.push({
                    inputName:document.getElementById(inputName).value,
                    type:document.getElementById(type).value,
                    inputIntroduction:document.getElementById(inputDetail).value,
                    suffix:document.getElementById(inputSufficcx).value
                })
            }else if(document.getElementById(type).value=="directory"){
                inputinfo.push({
                    inputName:document.getElementById(inputName).value,
                    type:document.getElementById(type).value,
                    inputIntroduction:document.getElementById(inputDetail).value,
                    suffix:""
                })
            }

        }
        registerinfo.inputCount=inputinfo;
        output_count_num=document.getElementById("outputNum").innerHTML;

        var outputinfo=new Array();
        for(var i=0;i< output_count_num;i++)
        {
            var temp=i+1;
            var outputName= "output_name" +temp;
            var type = "output_type"+temp;
            var outputDetail = "output_introduction" +temp;
            var outputSuffix = "output_suffix"+temp;
            if(document.getElementById(type).value=="file"){
                outputinfo.push({
                    outputName:document.getElementById(outputName).value,
                    type:document.getElementById(type).value,
                    outputIntroduction:document.getElementById(outputDetail).value,
                    suffix:document.getElementById(outputSuffix).value
                })
            }else if(document.getElementById(type).value=="directory"){
                outputinfo.push({
                    outputName:document.getElementById(outputName).value,
                    type:document.getElementById(type).value,
                    outputIntroduction:document.getElementById(outputDetail).value,
                    suffix:""
                })
            }
        }
        registerinfo.outputCount=outputinfo;
        params_count_num=document.getElementById("paramNum").innerHTML
        var paramInfo=new Array();
        for(var i=0;i<params_count_num;i++)
        {
            var temp=i+1;
            var paramName =  "param_id" +temp;
            var paramSymbol=  "param_symbol" +temp;
            var paramDetail=  "param_introduction" + temp;
            var paramDefaultValue = "paramDefaultValue"+temp;
            paramInfo.push({
                paramSymbol:document.getElementById(paramSymbol).value,
                paramType:document.getElementById(paramName).value,
                paramIntroduction:document.getElementById(paramDetail).value,
                paramDefaultValue:document.getElementById(paramDefaultValue).value
            })
        }
        registerinfo.paramsCount=paramInfo;
        registerinfo.version=document.getElementById("version").value;
        registerinfo.introduction=document.getElementById("introduction").value;
        registerinfo.algorithmType=document.getElementById("algorithm_type").value;
        registerinfo.postfix=document.getElementById("postfix").value;
        registerinfo.companyName=document.getElementById("company_name").value;
        registerinfo.platform=document.getElementById("platform").value;
        // registerinfo.minCpuIdle=(document.getElementById("Min_CPU").value/100);
        // registerinfo.minRamRemaining=document.getElementById("Min_intrinsic").value;
        var cpunum = document.getElementById("cpunum").value;
        if(cpunum==""){
            registerinfo.cpuNum = 0;
        }else{
            registerinfo.cpuNum = cpunum;
        }
        registerinfo.algorithmFunction=document.getElementById("algorithm_function").value;
        var GPU=document.getElementsByName("GPU");
        for(var i=0;i<GPU.length;i++)
        {
            if(GPU[i].checked)
            {
                registerinfo.isContainGpu=GPU[i].value;
                break;
            }
            else
            {
                continue;
            }
        }
        var MPI=document.getElementsByName("MPI")
        for(var i=0;i<MPI.length;i++)
        {
            if(MPI[i].checked)
            {
                registerinfo.isUseMpi=MPI[i].value;
                break;
            }
            else
            {
                continue;
            }
        }
        var genetic=document.getElementsByName("genetic")
        for(var i=0;i<genetic.length;i++)
        {
            if(genetic[i].checked)
            {
                registerinfo.genetic=genetic[i].value;
                break;
            }
            else
            {
                continue;
            }
        }
        console.log(registerinfo);
        var fileinfo=document.getElementById("file");
        var registerinfo_json = JSON.stringify(registerinfo);
        console.log(registerinfo_json);
        var file=new FormData();
        file.append('algorithm',registerinfo_json);
        file.append('file',fileinfo.files[0]);

        var validators = new  InputValidators();

        validators.importStrategies(validationStrategies);

        validators.addValidationStrategy('isEqual',  function(element, errMsg, value1, value2) {
            if(value1 !== value2) {
                return this.buildInvalidObj(element, errMsg, value1 );
            }
        });
        //算法名称
        var ag_name = document.getElementById('name');
        validators.addValidator('isNoEmpty', ag_name, '算法名称未填写，请返回填写', ag_name.value);
        // validators.addValidator('minLength:3', ag_name, '算法名称的字符个数必须是3到20个', ag_name.value);
        // validators.addValidator('maxLength:20', ag_name, '算法名称的字符个数必须是3到20个', ag_name.value);
        //算法版本号
        var ag_version = document.getElementById('version');
        validators.addValidator('isNoEmpty', ag_version, '算法版本未填写，请返回填写', ag_version.value);
        //算法功能选择
        var ag_function = document.getElementById('algorithm_function');
        validators.addValidator('isNoEmpty', ag_function, '算法功能未选择，请返回选择', ag_function.value);
        //算法类型选择
        var ag_type = document.getElementById('algorithm_type');
        validators.addValidator('isNoEmpty', ag_type, '算法类型未选择，请返回选择', ag_type.value);
        //文件
        var paramFlieresString=$("#file");
        var str = paramFlieresString.val().split("\\");
        var paramFlieres = str[str.length-1];
        validators.addValidator('isNoEmpty', paramFlieresString, '没有选择文件，请返回选择文件', paramFlieres);
        //算法研制单位
        var ag_company = document.getElementById('company_name');
        validators.addValidator('isNoEmpty', ag_company, '算法研制单位未选择，请返回选择', ag_company.value);
        //算法简介
        var ag_introduction =document.getElementById("introduction");
        validators.addValidator('isNoEmpty', ag_introduction, '算法简介未填写，请返回填写', ag_introduction.value);
        // validators.addValidator('minLength:3', ag_introduction, '算法简介包含的字符少于3个字符，请返回选择', ag_introduction.value);
        // validators.addValidator('maxLength:250', ag_introduction, '算法类型未选择，请返回选择', ag_introduction.value);
        //算法后缀
        var ag_postfix = document.getElementById('postfix');
        validators.addValidator('isNoEmpty', ag_postfix, '算法后缀未选择，请返回选择', ag_postfix.value);
        //算法使用平台
        var ag_platform = document.getElementById('platform');
        validators.addValidator('isNoEmpty', ag_platform, '算法使用平台未选择，请返回选择', ag_platform.value);
        //是否使用gpu
        var ag_gpu=document.getElementsByName("GPU");
        validators.addValidator('isCheck', ag_gpu, '请选择是否使用GPU', ag_gpu);
        //是否使用MPI
        var ag_mpi=document.getElementsByName("MPI");
        validators.addValidator('isCheck', ag_mpi, '请选择是否使用MPI', ag_mpi);
        //检查cpu个数是否正确
        if($("input[name=MPI]:checked").attr("id")=="is_use_mpi"){
            var ag_cpunum = document.getElementById("cpunum")
            validators.addValidator('isInteger', ag_cpunum, '请正确填写CPU个数', ag_cpunum.value);
        }
        //是否是遗留算法
        var ag_genetic=document.getElementsByName("genetic");
        validators.addValidator('isCheck', ag_genetic, '请选择是否是遗留算法', ag_genetic);

        // for(var i = 0;i<input_count_num;i++){
        //     var temp = i+1;
        //     var type = "input_type"+temp;
        //     if(document.getElementById(type).value=="file"){
        //         var inputSuffix = "input_suffix"+temp;
        //         var ag_inputSuffix = document.getElementById(inputSuffix);
        //         validators.addValidator('isNotEmpty', ag_inputSuffix, '请正确填写第'+temp+'个输入参数的后缀,后缀以“.”开头且长度不小于1', ag_inputSuffix.value);
        //     }
        // }
        //
        // for(var i = 0;i<output_count_num;i++){
        //     var temp = i+1;
        //     var type = "output_type"+temp;
        //     if(document.getElementById(type).value=="file"){
        //         var outputSuffix = "output_suffix"+temp;
        //         var ag_outputSuffix = document.getElementById(outputSuffix);
        //         validators.addValidator('isNotEmpty', ag_outputSuffix, '请正确填写第'+temp+'个输出参数的后缀,后缀以“.”开头且长度不小于1', ag_outputSuffix.value);
        //     }
        // }

        var result = validators.check();
        if(result){
            layer.msg(result.errMsg);
            // alert(result.errMsg);
            result.element.focus();
            result.element.select();
            return false;
        }

        $.ajax({
            type:"POST",
            url:constUrl+"RegisterAlgorithm",
            processData: false,
            contentType: false,
            data: file,
            success:function(responseText){
                var res = JSON.stringify(responseText);
                responseText=eval("("+responseText+")");
                if(responseText.result==true)
                {
                    layer.confirm('添加成功！',{
                        btn:['确定']
                    },function () {
                        window.location.href=constUrl+ "views/algorithm/list.action";
                    })
                }
                else{

                    layer.msg(responseText.message+",请检查是否填写完全！");
                }

            },
            error:function(responseText) {
                isSubmit = false;
                layer.msg('添加失败！!');
            },
        })
    }

}

//验证准备
  //输入验证器
  function InputValidators(){
      this.validators = [];
      this.strategies = {};
  }

  //添加验证方法
  //参数:
  //  rule: 验证策略字符串
  //  element: 被验证的dom元素
  //  errMsg: 验证失败时显示的提示信息
  //  value: 被验证的值
  InputValidators.prototype.addValidator = function(rule, element, errMsg, value) {
      var that = this;
      var ruleElements = rule.split(":");

      this.validators.push(function() {
          var strategy = ruleElements.shift();
          var params = ruleElements;
          params.unshift(value);
          params.unshift(errMsg);
          params.unshift(element);

          return that.strategies[strategy].apply(that, params);
      });
  };

  //添加验证策略函数
  //参数:
  //  name: 策略名称
  //  strategy: 策略函数
  InputValidators.prototype.addValidationStrategy = function(name, strategy){
      this.strategies[name] = strategy;
  };

  //从策略对象导入验证策略函数
  //参数:
  //  strategies: 包含各种策略函数的对象
  InputValidators.prototype.importStrategies = function(strategies) {
      for(var strategyName in strategies) {
          this.addValidationStrategy(strategyName, strategies[strategyName]);
      }
  };

  //验证失败时，将相关的错误信息打包返回
  //参数:
  //  element: dom元素
  //   errMsg: 验证失败时的提示消息
  //    value: 被验证的值
  InputValidators.prototype.buildInvalidObj = function(element, errMsg, value){
      return {
          'value': value,
          'element': element,
          'errMsg': errMsg
      };
  };

  //开始验证
  InputValidators.prototype.check = function() {
      for(var i = 0, validator; validator = this.validators[i++];){
          var result = validator();
          if(result) {
              return result;
          }
      }
  };

  //验证策略对象，包含默认的验证策略函数
  var validationStrategies = {
      isNoEmpty: function(element, errMsg, value) {
          if(value === '') {
              return this.buildInvalidObj(element, errMsg, value );
          }
      },
      isNoUndefined: function(element, errMsg, value) {
          if(value === "undefined") {
              return this.buildInvalidObj(element, errMsg, value );
          }
      },
      isInteger:function (element, errMsg, value) {
          var reg = /^[0-9]*[1-9][0-9]*$/ ;
          if(!reg.test(value)){
              return this.buildInvalidObj(element, errMsg, value);
          }
      },
      isRight:function (element, errMsg, value) {
          if(value>100){
              return this.buildInvalidObj(element, errMsg, value);
          }
      },
      isNotEmpty:function (element, errMsg, value) {
        var fdstrat = value.indexOf(".");
        if(fdstrat==-1||value.length<=1){
            return this.buildInvalidObj(element, errMsg, value);
        }
      },
      isCheck:function (element, errMsg, value) {
          var isValue="";
          for(var i=0;i<value.length;i++)
          {
              if(value[i].checked)
              {
                  isValue=value[i].value;
                  break;
              }
              else
              {
                  continue;
              }
          }

        if(isValue==""){
            return this.buildInvalidObj(element, errMsg, value);
        }
      },
      minLength: function(element, errMsg, value, length) {
          if(value.length < length){
              return this.buildInvalidObj(element, errMsg, value);
          }
      },

      maxLength: function(element, errMsg, value, length) {
          if(value.length > length){
              return this.buildInvalidObj(element, errMsg, value);
          }
      },

      isMail: function(element, errMsg, value, length) {
          var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
          if(!reg.test(value)){
              return this.buildInvalidObj(element, errMsg, value);
          }
      }
  };

//验证表单
$(document).ready(function(){
    $("#name_div").hide();
    $("#version_div").hide();
    $("#version_div2").hide();
    $("#company_name_div").hide();
    $("#company_name_div2").hide();
    $("#introduction_div").hide();
    $("#introduction_div2").hide();
    $("#Min_intrinsic_div").hide();
    $("#Min_CPU_div").hide();
    $("#agfuction_div").hide();
    $("#agtype_div").hide();
    $("#postfix_div").hide();
    $("#platform_div").hide();
    $("#GPU_div").hide();
    $("#MPI_div").hide();
    $("#isLEft_div").hide();
    $("#cpunum_div").hide();



   //算法名称验证
    $("#name").blur(function(){
        var Name=$("#name").val();
        if(Name!==""){
            $("#version").focus();
            $("#name_div").hide();
            $("#name").css("border-color","#1ece20");
        }else{
            $("#name").css("border-color","red");
            $("#name_div").css("color","red")
            $("#name_div").show();
        }
    });


    //算法版本验证
    $("#version").blur(function(){
        var Version=$("#version").val();

        if(Version!==""){
            $("#algorithm_function").focus();
            $("#version").css("background-color","white");
            $("#version").css("border-color","#1ece20");
            $("#version_div").hide();
        }else{
            $("#version").css("border-color","red");
            $("#version_div").css("color","red");
            $("#version_div2").hide();
            $("#version_div").show();
        }
    });

    //算法功能选择
    $("#algorithm_function").blur(function(){
        var agfunction=$("#algorithm_function").val();
        if(agfunction!==""&&agfunction!==null){
            $("#algorithm_type").focus();
            $("#agfuction_div").hide();
            $("#algorithm_function").css("border-color","#1ece20");
        }else{
            $("#algorithm_function").css("border-color","red");
            $("#agfuction_div").css("color","red")
            $("#agfuction_div").show();
        }
    });
//算法类型验证
    $("#algorithm_type").blur(function(){
        var agtype=$("#algorithm_type").val();
        if(agtype!==""&&agtype!==null){
            $("#company_name").focus();
            $("#agtype_div").hide();
            $("#algorithm_type").css("border-color","#1ece20");
        }else{
            $("#algorithm_type").css("border-color","red");
            $("#agtype_div").css("color","red")
            $("#agtype_div").show();
        }
    });
//
    $("#company_name").blur(function(){
        var Company_name=$("#company_name").val();
        console.log(Company_name);
        if(Company_name!=null){
            $("#introduction").focus();
            $("#company_name_div").hide();
            $("#company_name").css("border-color","#1ece20");
        }else{
            $("#company_name").css("border-color","red");
            $("#company_name_div").css("color","red")
            $("#company_name_div").show();
        }
    });

    $("#introduction").blur(function(){
        var introduction=$("#introduction").val();
        if(introduction!==""){
            $("#postfix").focus();
            $("#introduction_div").hide();
            $("#introduction").css("border-color","#1ece20");
        }else{
            $("#introduction").css("border-color","red");
            $("#introduction_div").css("color","red")
            $("#introduction_div").show();
        }
    });
//算法后缀验证
    $("#postfix").blur(function(){
        var postfix=$("#postfix").val();
        if(postfix!==""&&postfix!==null){
            $("#platform").focus();
            //$("#name_div").empty();
            $("#postfix_div").hide();
            $("#postfix").css("border-color","#1ece20");
        }else{
            //$("#name_div").empty();
            //$("#name_div").hide();
            $("#postfix").css("border-color","red");
            $("#postfix_div").css("color","red")
            $("#postfix_div").html("请选择算法后缀");
            $("#postfix_div").show();
        }
    });
    //算法使用平台验证
    $("#platform").blur(function(){
        var platform=$("#platform").val();
        if(platform!==""&&platform!==null){
           /* $("#platform").focus();*/
            $("#platform_div").hide();
            $("#platform").css("border-color","#1ece20");
        }else{
            //$("#name_div").empty();
            //$("#name_div").hide();
            $("#platform").css("border-color","red");
            $("#platform_div").css("color","red")
            $("#platform_div").html("请选择使用平台");
            $("#platform_div").show();
        }
    });
   /* $("#cpunum_div").blur(function () {
        var cpunum = $("#cpunum").val();
        var reg = /^[0-9]*[1-9][0-9]*$/ ;
        if(cpunum!=""&&reg.test(cpunum)){
            $("#cpunum").css("background-color","white");
            $("#check_cpunum_div").hide();
            $("#cpunum").css("border-color","#1ece20");
        }else{
            $("#cpunum").css("border-color","red");
            $("#check_cpunum_div").css("color","red");
            $("#check_cpunum_div").html("请正确填写CPU个数");
            $("#check_cpunum_div").show();
        }
    })*/
    //最小内存剩余验证
  /*  $("#Min_intrinsic").blur(function(){
        var Min_intrinsic=$("#Min_intrinsic").val();
        var reg = /^[0-9]+$/;
        if(Min_intrinsic!==""&&reg.test(Min_intrinsic)){
            $("#Min_intrinsic").css("background-color","white");
            $("#Min_intrinsic_div").hide();
            $("Min_CPU_div").focus();
            $("#Min_intrinsic").css("border-color","#1ece20");
        }else{
            if(Min_intrinsic===""){
                $("#Min_intrinsic").css("border-color","red");
                $("#Min_intrinsic_div").css("color","red");
                $("#Min_intrinsic_div").html("请填写最小内存剩余");
                $("#Min_intrinsic_div").show();
            }else if(!reg.test(Min_intrinsic)){
                $("#Min_intrinsic").css("border-color","red");
                $("#Min_intrinsic_div").css("color","red");
                $("#Min_intrinsic_div").html("最小内存剩余是正整数，请正确填写");
                $("#Min_intrinsic_div").show();
            }

        }
    });*/
//CPU空闲验证
  /*  $("#Min_CPU").blur(function(){
        var Min_CPU=$("#Min_CPU").val();
        var reg = /^[0-9]+$/;
        if(Min_CPU!==""&&reg.test(Min_CPU)&&Min_CPU<=100){
            $("#Min_CPU").css("background-color","white");
            $("#Min_CPU_div").hide();
            $("#Min_CPU").css("border-color","#1ece20");
        }else{
            if(Min_CPU==""){
                $("#Min_CPU").css("border-color","red");
                $("#Min_CPU_div").css("color","red")
                $("#Min_CPU_div").html("请填写最小CPU空闲");
                $("#Min_CPU_div").show();
            }else if(Min_CPU>100){
                $("#Min_CPU").css("border-color","red");
                $("#Min_CPU_div").css("color","red")
                $("#Min_CPU_div").html("CPU空闲是1-100的正整数，请正确填写");
                $("#Min_CPU_div").show();
            }else if(!reg.test(Min_CPU)){
                $("#Min_CPU").css("border-color","red");
                $("#Min_CPU_div").css("color","red")
                $("#Min_CPU_div").html("CPU空闲是1-100的正整数，请正确填写");
                $("#Min_CPU_div").show();
            }
        }
    });*/
});

function fileShowMess() {
    var paramFlieresString=$("#file").val();
    var str = paramFlieresString.split("\\");
    var paramFlieres = str[str.length-1];
    if(paramFlieres!=""){
        $('#fileShow_div').html(paramFlieres);
        $("#fileShow_div").show();

    }else{
        $('#fileShow_div').html('您还没有输入任何东西');
        $("#fileShow_div").show();
    }
}

  $("input[name=MPI]").click(function(){

      switch($("input[name=MPI]:checked").attr("id")){
          case "is_use_mpi":
              $("#cpunum_div").show();
              break;
          case "no_mpi":
              document.getElementById("cpunum").value = "";
              $("#cpunum_div").hide();

              break;
          default:
              break;
      }
  });
